<template>
  <a-modal :title="modalTitle" :visible="visible" width="1200px" :maskClosable="false" @cancel="visible = false">
    <template>
      <entity-view @submit="submit" ref="baseForm" :model="beanInfo" :operator-type="operatorType">

        <form-item
          label="商户等级代码"
          v-model="beanInfo.mchntLevelCode"
          prop="mchntLevelCode"
          v-if="operatorType != 'add'"
          :disabled="true"
        ></form-item>
        <form-item
          label="商户等级名称"
          v-model="beanInfo.mchntLevelName"
          prop="mchntLevelName"
          :disabled="true"
        ></form-item>
        <form-item
          label="商户等级描述"
          v-model="beanInfo.mchntLevelDesc"
          prop="mchntLevelDesc"
          :disabled="true"
        ></form-item>
        <form-item label="审核拒绝原因" prop="auditRefuseReason" v-model="beanInfo.auditRefuseReason"
                   :disabled="this.operatorType!== 'chk'" input-type="textarea"></form-item>
      </entity-view>
    </template>
    <template v-slot:footer>
      <a-space>
        <a-button type="primary" @click="submit('pass')">审批通过</a-button>
        <a-button type="primary" @click="submit('back')">审批退回</a-button>
        <a-button type="primary" @click="visible = false">关闭</a-button>
      </a-space>
    </template>
  </a-modal>
</template>

<script>
  import EntityView from "../../../../components/common/entityView/EntityView.vue";
  import FormItem from "../../../../components/common/entityView/FormItem.vue";

  export default {
    name: "MchntLevelChk",
    components: {EntityView, FormItem},
    data: function () {
      return {
        beanInfo: {},
        modalVisible: false,
        modalTitle: '',
        operatorType: '',
        loading: false,
        visible: false,

      }
    },
    methods: {

      openModal(type = 'view', beanInfo) {
        const modalName = '商户等级'
        this.modalTitle = {chk: `${modalName}审核`, chkview: `${modalName}审核详情`}[type]
        this.modalVisible = true;
        this.visible = true;
        this.$nextTick(() => {
          this.operatorType = type
          this.setBeanInfo(type, beanInfo.instId, beanInfo.id);
        })
      },

      async submit(opt) {
        const res = await this.$refs.baseForm.validate()
        if (res) {
          const params = this.beanInfo;
          params.opt = opt;
          params.optFlag = this.operatorType;

          if (opt !== "pass") {
            if (params.auditRefuseReason === "") {
              this.$message.error('请输入审核拒绝原因！')
              return;
            }
          }
          const res = await this.$post('/admin/mcmp/bMchntLevelInfo/edit', params)
          if (res.status === 200) {
            this.$message.success('保存成功！');
            this.visible=false;
            this.$emit("ok");

          } else {
            this.$message.error(res.data.message)
            return false
          }
        }
      },

      setBeanInfo(optFlag, instId, id) {
        this.getOne(optFlag, instId, id)
      },

      async getOne(optFlag, instId, id) {
        try {
          const res = await this.$get('/admin/mcmp/bMchntLevelInfo/edit', {
            optFlag, instId, id
          })

          this.beanInfo = res.data.entity;
        } catch (e) {
          console.error(e)
        }
      },

    }

  }
</script>


<style scoped>
</style>
